{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Installing hub:\u001b[35m/\u001b[0m\u001b[35m/guardrails/\u001b[0m\u001b[95mregex_match...\u001b[0m\n",
      "✅Successfully installed guardrails/regex_match!\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "! guardrails hub install hub://guardrails/regex_match --quiet"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "chat_history = \"\"\"\n",
    "nelson and murdock: i need a pickup 797 9th Avenue, manila envelope, June 3 10:00am with dropoff 10:30am Courthouse, 61 Center Street C/O frank james\n",
    "operator: quote - $23.00\n",
    "neslon and murdock: perfect, we accept the quote\n",
    "operator: 797 9th ave, 10:00am pickup comfirmed\n",
    "abc flowers: i need a pickup of a flowers from abc flowers at 21 3rd street at 11:00am on june 2 with a dropoff at 75th Ave at 5:30pm same day\n",
    "operator: 21 3rd street flowers quote - $14.50\n",
    "abc flowers: accepted\n",
    "polk and wardell: i need a pickup of a bagels from Bakers Co at 331 5th street at 11:00am on june 3 with a dropoff at 75th Ave at 5:30pm same day\n",
    "operator: 331 5th street bagels quote - $34.50\n",
    "polk and wardell: accepted\n",
    "\"\"\"\n",
    "\n",
    "prompt = \"\"\"\n",
    "From the chat exchanges below extract a schedule of deliveries.\n",
    "Chats:\n",
    "${chat_history}\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">[</span>\n",
       "    <span style=\"font-weight: bold\">{</span>\n",
       "        <span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'function'</span>,\n",
       "        <span style=\"color: #008000; text-decoration-color: #008000\">'function'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "            <span style=\"color: #008000; text-decoration-color: #008000\">'name'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'gd_response_tool'</span>,\n",
       "            <span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'A tool for generating responses to guardrails. It must be called last in every </span>\n",
       "<span style=\"color: #008000; text-decoration-color: #008000\">response.'</span>,\n",
       "            <span style=\"color: #008000; text-decoration-color: #008000\">'parameters'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'$defs'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "                    <span style=\"color: #008000; text-decoration-color: #008000\">'Delivery'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "                        <span style=\"color: #008000; text-decoration-color: #008000\">'properties'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "                            <span style=\"color: #008000; text-decoration-color: #008000\">'custome_name'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'customer name'</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'title'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'Custome Name'</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'string'</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'validators'</span>: <span style=\"font-weight: bold\">[{</span><span style=\"color: #008000; text-decoration-color: #008000\">'rail_alias'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'guardrails/regex_match'</span><span style=\"font-weight: bold\">}]</span>\n",
       "                            <span style=\"font-weight: bold\">}</span>,\n",
       "                            <span style=\"color: #008000; text-decoration-color: #008000\">'pickup_time'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'date and time of pickup'</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'title'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'Pickup Time'</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'string'</span>\n",
       "                            <span style=\"font-weight: bold\">}</span>,\n",
       "                            <span style=\"color: #008000; text-decoration-color: #008000\">'pickup_location'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'address of pickup'</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'title'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'Pickup Location'</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'string'</span>\n",
       "                            <span style=\"font-weight: bold\">}</span>,\n",
       "                            <span style=\"color: #008000; text-decoration-color: #008000\">'dropoff_time'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'date and time of dropoff'</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'title'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'Dropoff Time'</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'string'</span>\n",
       "                            <span style=\"font-weight: bold\">}</span>,\n",
       "                            <span style=\"color: #008000; text-decoration-color: #008000\">'dropoff_location'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'address of dropoff'</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'title'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'Dropoff Location'</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'string'</span>\n",
       "                            <span style=\"font-weight: bold\">}</span>,\n",
       "                            <span style=\"color: #008000; text-decoration-color: #008000\">'price'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'price of delivery with currency symbol included'</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'title'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'Price'</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'string'</span>\n",
       "                            <span style=\"font-weight: bold\">}</span>\n",
       "                        <span style=\"font-weight: bold\">}</span>,\n",
       "                        <span style=\"color: #008000; text-decoration-color: #008000\">'required'</span>: <span style=\"font-weight: bold\">[</span>\n",
       "                            <span style=\"color: #008000; text-decoration-color: #008000\">'custome_name'</span>,\n",
       "                            <span style=\"color: #008000; text-decoration-color: #008000\">'pickup_time'</span>,\n",
       "                            <span style=\"color: #008000; text-decoration-color: #008000\">'pickup_location'</span>,\n",
       "                            <span style=\"color: #008000; text-decoration-color: #008000\">'dropoff_time'</span>,\n",
       "                            <span style=\"color: #008000; text-decoration-color: #008000\">'dropoff_location'</span>,\n",
       "                            <span style=\"color: #008000; text-decoration-color: #008000\">'price'</span>\n",
       "                        <span style=\"font-weight: bold\">]</span>,\n",
       "                        <span style=\"color: #008000; text-decoration-color: #008000\">'title'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'Delivery'</span>,\n",
       "                        <span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'object'</span>\n",
       "                    <span style=\"font-weight: bold\">}</span>\n",
       "                <span style=\"font-weight: bold\">}</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'properties'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "                    <span style=\"color: #008000; text-decoration-color: #008000\">'deliveries'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'items'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'$ref'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'#/$defs/Delivery'</span><span style=\"font-weight: bold\">}</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'title'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'Deliveries'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'array'</span><span style=\"font-weight: bold\">}</span>\n",
       "                <span style=\"font-weight: bold\">}</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'required'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008000; text-decoration-color: #008000\">'deliveries'</span><span style=\"font-weight: bold\">]</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'object'</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'title'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'Schedule'</span>\n",
       "            <span style=\"font-weight: bold\">}</span>,\n",
       "            <span style=\"color: #008000; text-decoration-color: #008000\">'required'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008000; text-decoration-color: #008000\">'deliveries'</span><span style=\"font-weight: bold\">]</span>\n",
       "        <span style=\"font-weight: bold\">}</span>\n",
       "    <span style=\"font-weight: bold\">}</span>\n",
       "<span style=\"font-weight: bold\">]</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[1m[\u001b[0m\n",
       "    \u001b[1m{\u001b[0m\n",
       "        \u001b[32m'type'\u001b[0m: \u001b[32m'function'\u001b[0m,\n",
       "        \u001b[32m'function'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "            \u001b[32m'name'\u001b[0m: \u001b[32m'gd_response_tool'\u001b[0m,\n",
       "            \u001b[32m'description'\u001b[0m: \u001b[32m'A tool for generating responses to guardrails. It must be called last in every \u001b[0m\n",
       "\u001b[32mresponse.'\u001b[0m,\n",
       "            \u001b[32m'parameters'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "                \u001b[32m'$defs'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "                    \u001b[32m'Delivery'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "                        \u001b[32m'properties'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "                            \u001b[32m'custome_name'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "                                \u001b[32m'description'\u001b[0m: \u001b[32m'customer name'\u001b[0m,\n",
       "                                \u001b[32m'title'\u001b[0m: \u001b[32m'Custome Name'\u001b[0m,\n",
       "                                \u001b[32m'type'\u001b[0m: \u001b[32m'string'\u001b[0m,\n",
       "                                \u001b[32m'validators'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1m{\u001b[0m\u001b[32m'rail_alias'\u001b[0m: \u001b[32m'guardrails/regex_match'\u001b[0m\u001b[1m}\u001b[0m\u001b[1m]\u001b[0m\n",
       "                            \u001b[1m}\u001b[0m,\n",
       "                            \u001b[32m'pickup_time'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "                                \u001b[32m'description'\u001b[0m: \u001b[32m'date and time of pickup'\u001b[0m,\n",
       "                                \u001b[32m'title'\u001b[0m: \u001b[32m'Pickup Time'\u001b[0m,\n",
       "                                \u001b[32m'type'\u001b[0m: \u001b[32m'string'\u001b[0m\n",
       "                            \u001b[1m}\u001b[0m,\n",
       "                            \u001b[32m'pickup_location'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "                                \u001b[32m'description'\u001b[0m: \u001b[32m'address of pickup'\u001b[0m,\n",
       "                                \u001b[32m'title'\u001b[0m: \u001b[32m'Pickup Location'\u001b[0m,\n",
       "                                \u001b[32m'type'\u001b[0m: \u001b[32m'string'\u001b[0m\n",
       "                            \u001b[1m}\u001b[0m,\n",
       "                            \u001b[32m'dropoff_time'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "                                \u001b[32m'description'\u001b[0m: \u001b[32m'date and time of dropoff'\u001b[0m,\n",
       "                                \u001b[32m'title'\u001b[0m: \u001b[32m'Dropoff Time'\u001b[0m,\n",
       "                                \u001b[32m'type'\u001b[0m: \u001b[32m'string'\u001b[0m\n",
       "                            \u001b[1m}\u001b[0m,\n",
       "                            \u001b[32m'dropoff_location'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "                                \u001b[32m'description'\u001b[0m: \u001b[32m'address of dropoff'\u001b[0m,\n",
       "                                \u001b[32m'title'\u001b[0m: \u001b[32m'Dropoff Location'\u001b[0m,\n",
       "                                \u001b[32m'type'\u001b[0m: \u001b[32m'string'\u001b[0m\n",
       "                            \u001b[1m}\u001b[0m,\n",
       "                            \u001b[32m'price'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "                                \u001b[32m'description'\u001b[0m: \u001b[32m'price of delivery with currency symbol included'\u001b[0m,\n",
       "                                \u001b[32m'title'\u001b[0m: \u001b[32m'Price'\u001b[0m,\n",
       "                                \u001b[32m'type'\u001b[0m: \u001b[32m'string'\u001b[0m\n",
       "                            \u001b[1m}\u001b[0m\n",
       "                        \u001b[1m}\u001b[0m,\n",
       "                        \u001b[32m'required'\u001b[0m: \u001b[1m[\u001b[0m\n",
       "                            \u001b[32m'custome_name'\u001b[0m,\n",
       "                            \u001b[32m'pickup_time'\u001b[0m,\n",
       "                            \u001b[32m'pickup_location'\u001b[0m,\n",
       "                            \u001b[32m'dropoff_time'\u001b[0m,\n",
       "                            \u001b[32m'dropoff_location'\u001b[0m,\n",
       "                            \u001b[32m'price'\u001b[0m\n",
       "                        \u001b[1m]\u001b[0m,\n",
       "                        \u001b[32m'title'\u001b[0m: \u001b[32m'Delivery'\u001b[0m,\n",
       "                        \u001b[32m'type'\u001b[0m: \u001b[32m'object'\u001b[0m\n",
       "                    \u001b[1m}\u001b[0m\n",
       "                \u001b[1m}\u001b[0m,\n",
       "                \u001b[32m'properties'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "                    \u001b[32m'deliveries'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'items'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'$ref'\u001b[0m: \u001b[32m'#/$defs/Delivery'\u001b[0m\u001b[1m}\u001b[0m, \u001b[32m'title'\u001b[0m: \u001b[32m'Deliveries'\u001b[0m, \u001b[32m'type'\u001b[0m: \u001b[32m'array'\u001b[0m\u001b[1m}\u001b[0m\n",
       "                \u001b[1m}\u001b[0m,\n",
       "                \u001b[32m'required'\u001b[0m: \u001b[1m[\u001b[0m\u001b[32m'deliveries'\u001b[0m\u001b[1m]\u001b[0m,\n",
       "                \u001b[32m'type'\u001b[0m: \u001b[32m'object'\u001b[0m,\n",
       "                \u001b[32m'title'\u001b[0m: \u001b[32m'Schedule'\u001b[0m\n",
       "            \u001b[1m}\u001b[0m,\n",
       "            \u001b[32m'required'\u001b[0m: \u001b[1m[\u001b[0m\u001b[32m'deliveries'\u001b[0m\u001b[1m]\u001b[0m\n",
       "        \u001b[1m}\u001b[0m\n",
       "    \u001b[1m}\u001b[0m\n",
       "\u001b[1m]\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from rich import print\n",
    "from guardrails import Guard\n",
    "from guardrails.hub import RegexMatch\n",
    "from pydantic import BaseModel, Field\n",
    "from typing import List\n",
    "\n",
    "NAME_REGEX = \"^[A-Z][a-z]+\\\\s[A-Z][a-z]+$\"\n",
    "\n",
    "\n",
    "class Delivery(BaseModel):\n",
    "    custome_name: str = Field(\n",
    "        validators=[RegexMatch(regex=NAME_REGEX, on_fail=\"noop\")],\n",
    "        description=\"customer name\",\n",
    "    )\n",
    "    pickup_time: str = Field(description=\"date and time of pickup\")\n",
    "    pickup_location: str = Field(description=\"address of pickup\")\n",
    "    dropoff_time: str = Field(description=\"date and time of dropoff\")\n",
    "    dropoff_location: str = Field(description=\"address of dropoff\")\n",
    "    price: str = Field(description=\"price of delivery with currency symbol included\")\n",
    "\n",
    "\n",
    "class Schedule(BaseModel):\n",
    "    deliveries: List[Delivery]\n",
    "\n",
    "\n",
    "pydantic_guard = Guard.for_pydantic(Schedule)\n",
    "\n",
    "# Generate the function calling tool and add it to the list\n",
    "pydantic_guard_tools = pydantic_guard.json_function_calling_tool([])\n",
    "\n",
    "print(pydantic_guard_tools)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">[</span>\n",
       "    <span style=\"font-weight: bold\">{</span>\n",
       "        <span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'function'</span>,\n",
       "        <span style=\"color: #008000; text-decoration-color: #008000\">'function'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "            <span style=\"color: #008000; text-decoration-color: #008000\">'name'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'gd_response_tool'</span>,\n",
       "            <span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'A tool for generating responses to guardrails. It must be called last in every </span>\n",
       "<span style=\"color: #008000; text-decoration-color: #008000\">response.'</span>,\n",
       "            <span style=\"color: #008000; text-decoration-color: #008000\">'parameters'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'properties'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "                    <span style=\"color: #008000; text-decoration-color: #008000\">'deliveries'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "                        <span style=\"color: #008000; text-decoration-color: #008000\">'items'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "                            <span style=\"color: #008000; text-decoration-color: #008000\">'properties'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'customer_name'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'string'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'customer name'</span><span style=\"font-weight: bold\">}</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'pickup_time'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'string'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'date and time of pickup'</span><span style=\"font-weight: bold\">}</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'pickup_location'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'string'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'address of pickup'</span><span style=\"font-weight: bold\">}</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'dropoff_time'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'string'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'date and time of dropoff'</span><span style=\"font-weight: bold\">}</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'dropoff_location'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'string'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'address of dropoff'</span><span style=\"font-weight: bold\">}</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'price'</span>: <span style=\"font-weight: bold\">{</span>\n",
       "                                    <span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'string'</span>,\n",
       "                                    <span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'price of delivery with currency symbol included'</span>\n",
       "                                <span style=\"font-weight: bold\">}</span>\n",
       "                            <span style=\"font-weight: bold\">}</span>,\n",
       "                            <span style=\"color: #008000; text-decoration-color: #008000\">'required'</span>: <span style=\"font-weight: bold\">[</span>\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'customer_name'</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'pickup_time'</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'pickup_location'</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'dropoff_time'</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'dropoff_location'</span>,\n",
       "                                <span style=\"color: #008000; text-decoration-color: #008000\">'price'</span>\n",
       "                            <span style=\"font-weight: bold\">]</span>,\n",
       "                            <span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'object'</span>\n",
       "                        <span style=\"font-weight: bold\">}</span>,\n",
       "                        <span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'array'</span>\n",
       "                    <span style=\"font-weight: bold\">}</span>\n",
       "                <span style=\"font-weight: bold\">}</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'required'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008000; text-decoration-color: #008000\">'deliveries'</span><span style=\"font-weight: bold\">]</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'object'</span>\n",
       "            <span style=\"font-weight: bold\">}</span>,\n",
       "            <span style=\"color: #008000; text-decoration-color: #008000\">'required'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008000; text-decoration-color: #008000\">'deliveries'</span><span style=\"font-weight: bold\">]</span>\n",
       "        <span style=\"font-weight: bold\">}</span>\n",
       "    <span style=\"font-weight: bold\">}</span>\n",
       "<span style=\"font-weight: bold\">]</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[1m[\u001b[0m\n",
       "    \u001b[1m{\u001b[0m\n",
       "        \u001b[32m'type'\u001b[0m: \u001b[32m'function'\u001b[0m,\n",
       "        \u001b[32m'function'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "            \u001b[32m'name'\u001b[0m: \u001b[32m'gd_response_tool'\u001b[0m,\n",
       "            \u001b[32m'description'\u001b[0m: \u001b[32m'A tool for generating responses to guardrails. It must be called last in every \u001b[0m\n",
       "\u001b[32mresponse.'\u001b[0m,\n",
       "            \u001b[32m'parameters'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "                \u001b[32m'properties'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "                    \u001b[32m'deliveries'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "                        \u001b[32m'items'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "                            \u001b[32m'properties'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "                                \u001b[32m'customer_name'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'type'\u001b[0m: \u001b[32m'string'\u001b[0m, \u001b[32m'description'\u001b[0m: \u001b[32m'customer name'\u001b[0m\u001b[1m}\u001b[0m,\n",
       "                                \u001b[32m'pickup_time'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'type'\u001b[0m: \u001b[32m'string'\u001b[0m, \u001b[32m'description'\u001b[0m: \u001b[32m'date and time of pickup'\u001b[0m\u001b[1m}\u001b[0m,\n",
       "                                \u001b[32m'pickup_location'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'type'\u001b[0m: \u001b[32m'string'\u001b[0m, \u001b[32m'description'\u001b[0m: \u001b[32m'address of pickup'\u001b[0m\u001b[1m}\u001b[0m,\n",
       "                                \u001b[32m'dropoff_time'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'type'\u001b[0m: \u001b[32m'string'\u001b[0m, \u001b[32m'description'\u001b[0m: \u001b[32m'date and time of dropoff'\u001b[0m\u001b[1m}\u001b[0m,\n",
       "                                \u001b[32m'dropoff_location'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'type'\u001b[0m: \u001b[32m'string'\u001b[0m, \u001b[32m'description'\u001b[0m: \u001b[32m'address of dropoff'\u001b[0m\u001b[1m}\u001b[0m,\n",
       "                                \u001b[32m'price'\u001b[0m: \u001b[1m{\u001b[0m\n",
       "                                    \u001b[32m'type'\u001b[0m: \u001b[32m'string'\u001b[0m,\n",
       "                                    \u001b[32m'description'\u001b[0m: \u001b[32m'price of delivery with currency symbol included'\u001b[0m\n",
       "                                \u001b[1m}\u001b[0m\n",
       "                            \u001b[1m}\u001b[0m,\n",
       "                            \u001b[32m'required'\u001b[0m: \u001b[1m[\u001b[0m\n",
       "                                \u001b[32m'customer_name'\u001b[0m,\n",
       "                                \u001b[32m'pickup_time'\u001b[0m,\n",
       "                                \u001b[32m'pickup_location'\u001b[0m,\n",
       "                                \u001b[32m'dropoff_time'\u001b[0m,\n",
       "                                \u001b[32m'dropoff_location'\u001b[0m,\n",
       "                                \u001b[32m'price'\u001b[0m\n",
       "                            \u001b[1m]\u001b[0m,\n",
       "                            \u001b[32m'type'\u001b[0m: \u001b[32m'object'\u001b[0m\n",
       "                        \u001b[1m}\u001b[0m,\n",
       "                        \u001b[32m'type'\u001b[0m: \u001b[32m'array'\u001b[0m\n",
       "                    \u001b[1m}\u001b[0m\n",
       "                \u001b[1m}\u001b[0m,\n",
       "                \u001b[32m'required'\u001b[0m: \u001b[1m[\u001b[0m\u001b[32m'deliveries'\u001b[0m\u001b[1m]\u001b[0m,\n",
       "                \u001b[32m'type'\u001b[0m: \u001b[32m'object'\u001b[0m\n",
       "            \u001b[1m}\u001b[0m,\n",
       "            \u001b[32m'required'\u001b[0m: \u001b[1m[\u001b[0m\u001b[32m'deliveries'\u001b[0m\u001b[1m]\u001b[0m\n",
       "        \u001b[1m}\u001b[0m\n",
       "    \u001b[1m}\u001b[0m\n",
       "\u001b[1m]\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "rail = \"\"\"\n",
    "<rail version=\"0.1\">\n",
    "    <output>\n",
    "        <list name=\"deliveries\">\n",
    "            <object>\n",
    "                <string name=\"customer_name\" validators=\"hub://guardrails/regex_match: ^[A-Z][a-z]+\\\\s[A-Z][a-z]+$\" description=\"customer name\" on-fail-guardrails_regex_match=\"reask\" />\n",
    "                <string name=\"pickup_time\" description=\"date and time of pickup\" />\n",
    "                <string name=\"pickup_location\" description=\"address of pickup\" />\n",
    "                <string name=\"dropoff_time\" description=\"date and time of dropoff\" />\n",
    "                <string name=\"dropoff_location\" description=\"address of dropoff\" />\n",
    "                <string name=\"price\" description=\"price of delivery with currency symbol included\" />\n",
    "            </object>\n",
    "        </list>\n",
    "    </output>\n",
    "</rail>\n",
    "\"\"\"\n",
    "\n",
    "rail_guard = Guard.for_rail_string(rail)\n",
    "\n",
    "\n",
    "# Generate the function calling tool and add it to the list\n",
    "rail_guard_tools = rail_guard.json_function_calling_tool([])\n",
    "\n",
    "print(rail_guard_tools)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/dtam/dev/guardrails/guardrails/validator_service/__init__.py:85: UserWarning: Could not obtain an event loop. Falling back to synchronous validation.\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">ValidationOutcome</span><span style=\"font-weight: bold\">(</span>\n",
       "    <span style=\"color: #808000; text-decoration-color: #808000\">call_id</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'13988399296'</span>,\n",
       "    <span style=\"color: #808000; text-decoration-color: #808000\">raw_llm_output</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'{\"deliveries\":[{\"custome_name\":\"nelson and murdock\",\"pickup_time\":\"June 3 </span>\n",
       "<span style=\"color: #008000; text-decoration-color: #008000\">10:00am\",\"pickup_location\":\"797 9th Avenue\",\"dropoff_time\":\"June 3 10:30am\",\"dropoff_location\":\"Courthouse, 61 </span>\n",
       "<span style=\"color: #008000; text-decoration-color: #008000\">Center Street C/O frank james\",\"price\":\"$23.00\"},{\"custome_name\":\"abc flowers\",\"pickup_time\":\"June 2 </span>\n",
       "<span style=\"color: #008000; text-decoration-color: #008000\">11:00am\",\"pickup_location\":\"21 3rd street\",\"dropoff_time\":\"June 2 5:30pm\",\"dropoff_location\":\"75th </span>\n",
       "<span style=\"color: #008000; text-decoration-color: #008000\">Ave\",\"price\":\"$14.50\"},{\"custome_name\":\"polk and wardell\",\"pickup_time\":\"June 3 11:00am\",\"pickup_location\":\"331 5th</span>\n",
       "<span style=\"color: #008000; text-decoration-color: #008000\">street\",\"dropoff_time\":\"June 3 5:30pm\",\"dropoff_location\":\"75th Ave\",\"price\":\"$34.50\"}]}'</span>,\n",
       "    <span style=\"color: #808000; text-decoration-color: #808000\">validation_summaries</span>=<span style=\"font-weight: bold\">[</span>\n",
       "        <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">ValidationSummary</span><span style=\"font-weight: bold\">(</span>\n",
       "            <span style=\"color: #808000; text-decoration-color: #808000\">validator_name</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'RegexMatch'</span>,\n",
       "            <span style=\"color: #808000; text-decoration-color: #808000\">validator_status</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'fail'</span>,\n",
       "            <span style=\"color: #808000; text-decoration-color: #808000\">property_path</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'$.deliveries.0.custome_name'</span>,\n",
       "            <span style=\"color: #808000; text-decoration-color: #808000\">failure_reason</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'Result must match ^[A-Z][a-z]+\\\\s[A-Z][a-z]+$'</span>,\n",
       "            <span style=\"color: #808000; text-decoration-color: #808000\">error_spans</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>\n",
       "        <span style=\"font-weight: bold\">)</span>,\n",
       "        <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">ValidationSummary</span><span style=\"font-weight: bold\">(</span>\n",
       "            <span style=\"color: #808000; text-decoration-color: #808000\">validator_name</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'RegexMatch'</span>,\n",
       "            <span style=\"color: #808000; text-decoration-color: #808000\">validator_status</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'fail'</span>,\n",
       "            <span style=\"color: #808000; text-decoration-color: #808000\">property_path</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'$.deliveries.1.custome_name'</span>,\n",
       "            <span style=\"color: #808000; text-decoration-color: #808000\">failure_reason</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'Result must match ^[A-Z][a-z]+\\\\s[A-Z][a-z]+$'</span>,\n",
       "            <span style=\"color: #808000; text-decoration-color: #808000\">error_spans</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>\n",
       "        <span style=\"font-weight: bold\">)</span>,\n",
       "        <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">ValidationSummary</span><span style=\"font-weight: bold\">(</span>\n",
       "            <span style=\"color: #808000; text-decoration-color: #808000\">validator_name</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'RegexMatch'</span>,\n",
       "            <span style=\"color: #808000; text-decoration-color: #808000\">validator_status</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'fail'</span>,\n",
       "            <span style=\"color: #808000; text-decoration-color: #808000\">property_path</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'$.deliveries.2.custome_name'</span>,\n",
       "            <span style=\"color: #808000; text-decoration-color: #808000\">failure_reason</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'Result must match ^[A-Z][a-z]+\\\\s[A-Z][a-z]+$'</span>,\n",
       "            <span style=\"color: #808000; text-decoration-color: #808000\">error_spans</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>\n",
       "        <span style=\"font-weight: bold\">)</span>\n",
       "    <span style=\"font-weight: bold\">]</span>,\n",
       "    <span style=\"color: #808000; text-decoration-color: #808000\">validated_output</span>=<span style=\"font-weight: bold\">{</span>\n",
       "        <span style=\"color: #008000; text-decoration-color: #008000\">'deliveries'</span>: <span style=\"font-weight: bold\">[</span>\n",
       "            <span style=\"font-weight: bold\">{</span>\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'custome_name'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'nelson and murdock'</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'pickup_time'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'June 3 10:00am'</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'pickup_location'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'797 9th Avenue'</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'dropoff_time'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'June 3 10:30am'</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'dropoff_location'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'Courthouse, 61 Center Street C/O frank james'</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'price'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'$23.00'</span>\n",
       "            <span style=\"font-weight: bold\">}</span>,\n",
       "            <span style=\"font-weight: bold\">{</span>\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'custome_name'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'abc flowers'</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'pickup_time'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'June 2 11:00am'</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'pickup_location'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'21 3rd street'</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'dropoff_time'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'June 2 5:30pm'</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'dropoff_location'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'75th Ave'</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'price'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'$14.50'</span>\n",
       "            <span style=\"font-weight: bold\">}</span>,\n",
       "            <span style=\"font-weight: bold\">{</span>\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'custome_name'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'polk and wardell'</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'pickup_time'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'June 3 11:00am'</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'pickup_location'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'331 5th street'</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'dropoff_time'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'June 3 5:30pm'</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'dropoff_location'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'75th Ave'</span>,\n",
       "                <span style=\"color: #008000; text-decoration-color: #008000\">'price'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'$34.50'</span>\n",
       "            <span style=\"font-weight: bold\">}</span>\n",
       "        <span style=\"font-weight: bold\">]</span>\n",
       "    <span style=\"font-weight: bold\">}</span>,\n",
       "    <span style=\"color: #808000; text-decoration-color: #808000\">reask</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>,\n",
       "    <span style=\"color: #808000; text-decoration-color: #808000\">validation_passed</span>=<span style=\"color: #ff0000; text-decoration-color: #ff0000; font-style: italic\">False</span>,\n",
       "    <span style=\"color: #808000; text-decoration-color: #808000\">error</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>\n",
       "<span style=\"font-weight: bold\">)</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[1;35mValidationOutcome\u001b[0m\u001b[1m(\u001b[0m\n",
       "    \u001b[33mcall_id\u001b[0m=\u001b[32m'13988399296'\u001b[0m,\n",
       "    \u001b[33mraw_llm_output\u001b[0m=\u001b[32m'\u001b[0m\u001b[32m{\u001b[0m\u001b[32m\"deliveries\":\u001b[0m\u001b[32m[\u001b[0m\u001b[32m{\u001b[0m\u001b[32m\"custome_name\":\"nelson and murdock\",\"pickup_time\":\"June 3 \u001b[0m\n",
       "\u001b[32m10:00am\",\"pickup_location\":\"797 9th Avenue\",\"dropoff_time\":\"June 3 10:30am\",\"dropoff_location\":\"Courthouse, 61 \u001b[0m\n",
       "\u001b[32mCenter Street C/O frank james\",\"price\":\"$23.00\"\u001b[0m\u001b[32m}\u001b[0m\u001b[32m,\u001b[0m\u001b[32m{\u001b[0m\u001b[32m\"custome_name\":\"abc flowers\",\"pickup_time\":\"June 2 \u001b[0m\n",
       "\u001b[32m11:00am\",\"pickup_location\":\"21 3rd street\",\"dropoff_time\":\"June 2 5:30pm\",\"dropoff_location\":\"75th \u001b[0m\n",
       "\u001b[32mAve\",\"price\":\"$14.50\"\u001b[0m\u001b[32m}\u001b[0m\u001b[32m,\u001b[0m\u001b[32m{\u001b[0m\u001b[32m\"custome_name\":\"polk and wardell\",\"pickup_time\":\"June 3 11:00am\",\"pickup_location\":\"331 5th\u001b[0m\n",
       "\u001b[32mstreet\",\"dropoff_time\":\"June 3 5:30pm\",\"dropoff_location\":\"75th Ave\",\"price\":\"$34.50\"\u001b[0m\u001b[32m}\u001b[0m\u001b[32m]\u001b[0m\u001b[32m}\u001b[0m\u001b[32m'\u001b[0m,\n",
       "    \u001b[33mvalidation_summaries\u001b[0m=\u001b[1m[\u001b[0m\n",
       "        \u001b[1;35mValidationSummary\u001b[0m\u001b[1m(\u001b[0m\n",
       "            \u001b[33mvalidator_name\u001b[0m=\u001b[32m'RegexMatch'\u001b[0m,\n",
       "            \u001b[33mvalidator_status\u001b[0m=\u001b[32m'fail'\u001b[0m,\n",
       "            \u001b[33mproperty_path\u001b[0m=\u001b[32m'$.deliveries.0.custome_name'\u001b[0m,\n",
       "            \u001b[33mfailure_reason\u001b[0m=\u001b[32m'Result must match ^\u001b[0m\u001b[32m[\u001b[0m\u001b[32mA-Z\u001b[0m\u001b[32m]\u001b[0m\u001b[32m[\u001b[0m\u001b[32ma-z\u001b[0m\u001b[32m]\u001b[0m\u001b[32m+\\\\s\u001b[0m\u001b[32m[\u001b[0m\u001b[32mA-Z\u001b[0m\u001b[32m]\u001b[0m\u001b[32m[\u001b[0m\u001b[32ma-z\u001b[0m\u001b[32m]\u001b[0m\u001b[32m+$'\u001b[0m,\n",
       "            \u001b[33merror_spans\u001b[0m=\u001b[3;35mNone\u001b[0m\n",
       "        \u001b[1m)\u001b[0m,\n",
       "        \u001b[1;35mValidationSummary\u001b[0m\u001b[1m(\u001b[0m\n",
       "            \u001b[33mvalidator_name\u001b[0m=\u001b[32m'RegexMatch'\u001b[0m,\n",
       "            \u001b[33mvalidator_status\u001b[0m=\u001b[32m'fail'\u001b[0m,\n",
       "            \u001b[33mproperty_path\u001b[0m=\u001b[32m'$.deliveries.1.custome_name'\u001b[0m,\n",
       "            \u001b[33mfailure_reason\u001b[0m=\u001b[32m'Result must match ^\u001b[0m\u001b[32m[\u001b[0m\u001b[32mA-Z\u001b[0m\u001b[32m]\u001b[0m\u001b[32m[\u001b[0m\u001b[32ma-z\u001b[0m\u001b[32m]\u001b[0m\u001b[32m+\\\\s\u001b[0m\u001b[32m[\u001b[0m\u001b[32mA-Z\u001b[0m\u001b[32m]\u001b[0m\u001b[32m[\u001b[0m\u001b[32ma-z\u001b[0m\u001b[32m]\u001b[0m\u001b[32m+$'\u001b[0m,\n",
       "            \u001b[33merror_spans\u001b[0m=\u001b[3;35mNone\u001b[0m\n",
       "        \u001b[1m)\u001b[0m,\n",
       "        \u001b[1;35mValidationSummary\u001b[0m\u001b[1m(\u001b[0m\n",
       "            \u001b[33mvalidator_name\u001b[0m=\u001b[32m'RegexMatch'\u001b[0m,\n",
       "            \u001b[33mvalidator_status\u001b[0m=\u001b[32m'fail'\u001b[0m,\n",
       "            \u001b[33mproperty_path\u001b[0m=\u001b[32m'$.deliveries.2.custome_name'\u001b[0m,\n",
       "            \u001b[33mfailure_reason\u001b[0m=\u001b[32m'Result must match ^\u001b[0m\u001b[32m[\u001b[0m\u001b[32mA-Z\u001b[0m\u001b[32m]\u001b[0m\u001b[32m[\u001b[0m\u001b[32ma-z\u001b[0m\u001b[32m]\u001b[0m\u001b[32m+\\\\s\u001b[0m\u001b[32m[\u001b[0m\u001b[32mA-Z\u001b[0m\u001b[32m]\u001b[0m\u001b[32m[\u001b[0m\u001b[32ma-z\u001b[0m\u001b[32m]\u001b[0m\u001b[32m+$'\u001b[0m,\n",
       "            \u001b[33merror_spans\u001b[0m=\u001b[3;35mNone\u001b[0m\n",
       "        \u001b[1m)\u001b[0m\n",
       "    \u001b[1m]\u001b[0m,\n",
       "    \u001b[33mvalidated_output\u001b[0m=\u001b[1m{\u001b[0m\n",
       "        \u001b[32m'deliveries'\u001b[0m: \u001b[1m[\u001b[0m\n",
       "            \u001b[1m{\u001b[0m\n",
       "                \u001b[32m'custome_name'\u001b[0m: \u001b[32m'nelson and murdock'\u001b[0m,\n",
       "                \u001b[32m'pickup_time'\u001b[0m: \u001b[32m'June 3 10:00am'\u001b[0m,\n",
       "                \u001b[32m'pickup_location'\u001b[0m: \u001b[32m'797 9th Avenue'\u001b[0m,\n",
       "                \u001b[32m'dropoff_time'\u001b[0m: \u001b[32m'June 3 10:30am'\u001b[0m,\n",
       "                \u001b[32m'dropoff_location'\u001b[0m: \u001b[32m'Courthouse, 61 Center Street C/O frank james'\u001b[0m,\n",
       "                \u001b[32m'price'\u001b[0m: \u001b[32m'$23.00'\u001b[0m\n",
       "            \u001b[1m}\u001b[0m,\n",
       "            \u001b[1m{\u001b[0m\n",
       "                \u001b[32m'custome_name'\u001b[0m: \u001b[32m'abc flowers'\u001b[0m,\n",
       "                \u001b[32m'pickup_time'\u001b[0m: \u001b[32m'June 2 11:00am'\u001b[0m,\n",
       "                \u001b[32m'pickup_location'\u001b[0m: \u001b[32m'21 3rd street'\u001b[0m,\n",
       "                \u001b[32m'dropoff_time'\u001b[0m: \u001b[32m'June 2 5:30pm'\u001b[0m,\n",
       "                \u001b[32m'dropoff_location'\u001b[0m: \u001b[32m'75th Ave'\u001b[0m,\n",
       "                \u001b[32m'price'\u001b[0m: \u001b[32m'$14.50'\u001b[0m\n",
       "            \u001b[1m}\u001b[0m,\n",
       "            \u001b[1m{\u001b[0m\n",
       "                \u001b[32m'custome_name'\u001b[0m: \u001b[32m'polk and wardell'\u001b[0m,\n",
       "                \u001b[32m'pickup_time'\u001b[0m: \u001b[32m'June 3 11:00am'\u001b[0m,\n",
       "                \u001b[32m'pickup_location'\u001b[0m: \u001b[32m'331 5th street'\u001b[0m,\n",
       "                \u001b[32m'dropoff_time'\u001b[0m: \u001b[32m'June 3 5:30pm'\u001b[0m,\n",
       "                \u001b[32m'dropoff_location'\u001b[0m: \u001b[32m'75th Ave'\u001b[0m,\n",
       "                \u001b[32m'price'\u001b[0m: \u001b[32m'$34.50'\u001b[0m\n",
       "            \u001b[1m}\u001b[0m\n",
       "        \u001b[1m]\u001b[0m\n",
       "    \u001b[1m}\u001b[0m,\n",
       "    \u001b[33mreask\u001b[0m=\u001b[3;35mNone\u001b[0m,\n",
       "    \u001b[33mvalidation_passed\u001b[0m=\u001b[3;91mFalse\u001b[0m,\n",
       "    \u001b[33merror\u001b[0m=\u001b[3;35mNone\u001b[0m\n",
       "\u001b[1m)\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Add your OPENAI_API_KEY as an environment variable if it's not already set\n",
    "# import os\n",
    "# os.environ[\"OPENAI_API_KEY\"] = \"YOUR_API_KEY\"\n",
    "\n",
    "response = pydantic_guard(\n",
    "    model=\"gpt-4o\",\n",
    "    messages=[{\"role\": \"user\", \"content\": prompt}],\n",
    "    prompt_params={\"chat_history\": chat_history},\n",
    "    tools=pydantic_guard_tools,\n",
    "    tool_choice=\"required\",\n",
    ")\n",
    "\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Logs\n",
       "└── ╭────────────────────────────────────────────────── Step 0 ───────────────────────────────────────────────────╮\n",
       "    │ <span style=\"background-color: #e7dfeb\">╭─────────────────────────────────────────────── Messages ────────────────────────────────────────────────╮</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ ┏━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ ┃</span><span style=\"background-color: #e7dfeb; font-weight: bold\"> Role </span><span style=\"background-color: #e7dfeb\">┃</span><span style=\"background-color: #e7dfeb; font-weight: bold\"> Content                                                                                      </span><span style=\"background-color: #e7dfeb\">┃ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ ┡━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ │ user │                                                                                              │ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ │      │ From the chat exchanges below extract a schedule of deliveries.                              │ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ │      │ Chats:                                                                                       │ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ │      │                                                                                              │ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ │      │ nelson and murdock: i need a pickup 797 9th Avenue, manila envelope, June 3 10:00am with     │ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ │      │ dropoff 10:30am Courthouse, 61 Center Street C/O frank james                                 │ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ │      │ operator: quote - $23.00                                                                     │ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ │      │ neslon and murdock: perfect, we accept the quote                                             │ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ │      │ operator: 797 9th ave, 10:00am pickup comfirmed                                              │ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ │      │ abc flowers: i need a pickup of a flowers from abc flowers at 21 3rd street at 11:00am on    │ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ │      │ june 2 with a dropoff at 75th Ave at 5:30pm same day                                         │ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ │      │ operator: 21 3rd street flowers quote - $14.50                                               │ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ │      │ abc flowers: accepted                                                                        │ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ │      │ polk and wardell: i need a pickup of a bagels from Bakers Co at 331 5th street at 11:00am on │ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ │      │ june 3 with a dropoff at 75th Ave at 5:30pm same day                                         │ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ │      │ operator: 331 5th street bagels quote - $34.50                                               │ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ │      │ polk and wardell: accepted                                                                   │ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ │      │                                                                                              │ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ │      │                                                                                              │ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">│ └──────┴──────────────────────────────────────────────────────────────────────────────────────────────┘ │</span> │\n",
       "    │ <span style=\"background-color: #e7dfeb\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span> │\n",
       "    │ <span style=\"background-color: #f5f5dc\">╭──────────────────────────────────────────── Raw LLM Output ─────────────────────────────────────────────╮</span> │\n",
       "    │ <span style=\"background-color: #f5f5dc\">│ {\"deliveries\":[{\"custome_name\":\"nelson and murdock\",\"pickup_time\":\"June 3                               │</span> │\n",
       "    │ <span style=\"background-color: #f5f5dc\">│ 10:00am\",\"pickup_location\":\"797 9th Avenue\",\"dropoff_time\":\"June 3                                      │</span> │\n",
       "    │ <span style=\"background-color: #f5f5dc\">│ 10:30am\",\"dropoff_location\":\"Courthouse, 61 Center Street C/O frank                                     │</span> │\n",
       "    │ <span style=\"background-color: #f5f5dc\">│ james\",\"price\":\"$23.00\"},{\"custome_name\":\"abc flowers\",\"pickup_time\":\"June 2                            │</span> │\n",
       "    │ <span style=\"background-color: #f5f5dc\">│ 11:00am\",\"pickup_location\":\"21 3rd street\",\"dropoff_time\":\"June 2 5:30pm\",\"dropoff_location\":\"75th      │</span> │\n",
       "    │ <span style=\"background-color: #f5f5dc\">│ Ave\",\"price\":\"$14.50\"},{\"custome_name\":\"polk and wardell\",\"pickup_time\":\"June 3                         │</span> │\n",
       "    │ <span style=\"background-color: #f5f5dc\">│ 11:00am\",\"pickup_location\":\"331 5th street\",\"dropoff_time\":\"June 3 5:30pm\",\"dropoff_location\":\"75th     │</span> │\n",
       "    │ <span style=\"background-color: #f5f5dc\">│ Ave\",\"price\":\"$34.50\"}]}                                                                                │</span> │\n",
       "    │ <span style=\"background-color: #f5f5dc\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">╭─────────────────────────────────────────── Validated Output ────────────────────────────────────────────╮</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│ {                                                                                                       │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│     'deliveries': [                                                                                     │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│         {                                                                                               │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│             'custome_name': 'nelson and murdock',                                                       │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│             'pickup_time': 'June 3 10:00am',                                                            │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│             'pickup_location': '797 9th Avenue',                                                        │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│             'dropoff_time': 'June 3 10:30am',                                                           │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│             'dropoff_location': 'Courthouse, 61 Center Street C/O frank james',                         │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│             'price': '$23.00'                                                                           │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│         },                                                                                              │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│         {                                                                                               │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│             'custome_name': 'abc flowers',                                                              │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│             'pickup_time': 'June 2 11:00am',                                                            │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│             'pickup_location': '21 3rd street',                                                         │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│             'dropoff_time': 'June 2 5:30pm',                                                            │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│             'dropoff_location': '75th Ave',                                                             │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│             'price': '$14.50'                                                                           │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│         },                                                                                              │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│         {                                                                                               │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│             'custome_name': 'polk and wardell',                                                         │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│             'pickup_time': 'June 3 11:00am',                                                            │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│             'pickup_location': '331 5th street',                                                        │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│             'dropoff_time': 'June 3 5:30pm',                                                            │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│             'dropoff_location': '75th Ave',                                                             │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│             'price': '$34.50'                                                                           │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│         }                                                                                               │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│     ]                                                                                                   │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">│ }                                                                                                       │</span> │\n",
       "    │ <span style=\"background-color: #f0fff0\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span> │\n",
       "    ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\n",
       "</pre>\n"
      ],
      "text/plain": [
       "Logs\n",
       "└── ╭────────────────────────────────────────────────── Step 0 ───────────────────────────────────────────────────╮\n",
       "    │ \u001b[48;2;231;223;235m╭─\u001b[0m\u001b[48;2;231;223;235m──────────────────────────────────────────────\u001b[0m\u001b[48;2;231;223;235m Messages \u001b[0m\u001b[48;2;231;223;235m───────────────────────────────────────────────\u001b[0m\u001b[48;2;231;223;235m─╮\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m┏━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m┃\u001b[0m\u001b[1;48;2;231;223;235m \u001b[0m\u001b[1;48;2;231;223;235mRole\u001b[0m\u001b[1;48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m┃\u001b[0m\u001b[1;48;2;231;223;235m \u001b[0m\u001b[1;48;2;231;223;235mContent                                                                                     \u001b[0m\u001b[1;48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m┃\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m┡━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235muser\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m                                                                                            \u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m      \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235mFrom the chat exchanges below extract a schedule of deliveries.                             \u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m      \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235mChats:                                                                                      \u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m      \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m                                                                                            \u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m      \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235mnelson and murdock: i need a pickup 797 9th Avenue, manila envelope, June 3 10:00am with    \u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m      \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235mdropoff 10:30am Courthouse, 61 Center Street C/O frank james                                \u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m      \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235moperator: quote - $23.00                                                                    \u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m      \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235mneslon and murdock: perfect, we accept the quote                                            \u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m      \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235moperator: 797 9th ave, 10:00am pickup comfirmed                                             \u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m      \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235mabc flowers: i need a pickup of a flowers from abc flowers at 21 3rd street at 11:00am on   \u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m      \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235mjune 2 with a dropoff at 75th Ave at 5:30pm same day                                        \u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m      \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235moperator: 21 3rd street flowers quote - $14.50                                              \u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m      \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235mabc flowers: accepted                                                                       \u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m      \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235mpolk and wardell: i need a pickup of a bagels from Bakers Co at 331 5th street at 11:00am on\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m      \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235mjune 3 with a dropoff at 75th Ave at 5:30pm same day                                        \u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m      \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235moperator: 331 5th street bagels quote - $34.50                                              \u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m      \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235mpolk and wardell: accepted                                                                  \u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m      \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m                                                                                            \u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m      \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m                                                                                            \u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m│\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m└──────┴──────────────────────────────────────────────────────────────────────────────────────────────┘\u001b[0m\u001b[48;2;231;223;235m \u001b[0m\u001b[48;2;231;223;235m│\u001b[0m │\n",
       "    │ \u001b[48;2;231;223;235m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m │\n",
       "    │ \u001b[48;2;245;245;220m╭─\u001b[0m\u001b[48;2;245;245;220m───────────────────────────────────────────\u001b[0m\u001b[48;2;245;245;220m Raw LLM Output \u001b[0m\u001b[48;2;245;245;220m────────────────────────────────────────────\u001b[0m\u001b[48;2;245;245;220m─╮\u001b[0m │\n",
       "    │ \u001b[48;2;245;245;220m│\u001b[0m\u001b[48;2;245;245;220m \u001b[0m\u001b[48;2;245;245;220m{\"deliveries\":[{\"custome_name\":\"nelson and murdock\",\"pickup_time\":\"June 3 \u001b[0m\u001b[48;2;245;245;220m                             \u001b[0m\u001b[48;2;245;245;220m \u001b[0m\u001b[48;2;245;245;220m│\u001b[0m │\n",
       "    │ \u001b[48;2;245;245;220m│\u001b[0m\u001b[48;2;245;245;220m \u001b[0m\u001b[48;2;245;245;220m10:00am\",\"pickup_location\":\"797 9th Avenue\",\"dropoff_time\":\"June 3 \u001b[0m\u001b[48;2;245;245;220m                                    \u001b[0m\u001b[48;2;245;245;220m \u001b[0m\u001b[48;2;245;245;220m│\u001b[0m │\n",
       "    │ \u001b[48;2;245;245;220m│\u001b[0m\u001b[48;2;245;245;220m \u001b[0m\u001b[48;2;245;245;220m10:30am\",\"dropoff_location\":\"Courthouse, 61 Center Street C/O frank \u001b[0m\u001b[48;2;245;245;220m                                   \u001b[0m\u001b[48;2;245;245;220m \u001b[0m\u001b[48;2;245;245;220m│\u001b[0m │\n",
       "    │ \u001b[48;2;245;245;220m│\u001b[0m\u001b[48;2;245;245;220m \u001b[0m\u001b[48;2;245;245;220mjames\",\"price\":\"$23.00\"},{\"custome_name\":\"abc flowers\",\"pickup_time\":\"June 2 \u001b[0m\u001b[48;2;245;245;220m                          \u001b[0m\u001b[48;2;245;245;220m \u001b[0m\u001b[48;2;245;245;220m│\u001b[0m │\n",
       "    │ \u001b[48;2;245;245;220m│\u001b[0m\u001b[48;2;245;245;220m \u001b[0m\u001b[48;2;245;245;220m11:00am\",\"pickup_location\":\"21 3rd street\",\"dropoff_time\":\"June 2 5:30pm\",\"dropoff_location\":\"75th \u001b[0m\u001b[48;2;245;245;220m    \u001b[0m\u001b[48;2;245;245;220m \u001b[0m\u001b[48;2;245;245;220m│\u001b[0m │\n",
       "    │ \u001b[48;2;245;245;220m│\u001b[0m\u001b[48;2;245;245;220m \u001b[0m\u001b[48;2;245;245;220mAve\",\"price\":\"$14.50\"},{\"custome_name\":\"polk and wardell\",\"pickup_time\":\"June 3 \u001b[0m\u001b[48;2;245;245;220m                       \u001b[0m\u001b[48;2;245;245;220m \u001b[0m\u001b[48;2;245;245;220m│\u001b[0m │\n",
       "    │ \u001b[48;2;245;245;220m│\u001b[0m\u001b[48;2;245;245;220m \u001b[0m\u001b[48;2;245;245;220m11:00am\",\"pickup_location\":\"331 5th street\",\"dropoff_time\":\"June 3 5:30pm\",\"dropoff_location\":\"75th \u001b[0m\u001b[48;2;245;245;220m   \u001b[0m\u001b[48;2;245;245;220m \u001b[0m\u001b[48;2;245;245;220m│\u001b[0m │\n",
       "    │ \u001b[48;2;245;245;220m│\u001b[0m\u001b[48;2;245;245;220m \u001b[0m\u001b[48;2;245;245;220mAve\",\"price\":\"$34.50\"}]}\u001b[0m\u001b[48;2;245;245;220m                                                                               \u001b[0m\u001b[48;2;245;245;220m \u001b[0m\u001b[48;2;245;245;220m│\u001b[0m │\n",
       "    │ \u001b[48;2;245;245;220m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m╭─\u001b[0m\u001b[48;2;240;255;240m──────────────────────────────────────────\u001b[0m\u001b[48;2;240;255;240m Validated Output \u001b[0m\u001b[48;2;240;255;240m───────────────────────────────────────────\u001b[0m\u001b[48;2;240;255;240m─╮\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m{\u001b[0m\u001b[48;2;240;255;240m                                                                                                      \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m    'deliveries': [\u001b[0m\u001b[48;2;240;255;240m                                                                                    \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m        {\u001b[0m\u001b[48;2;240;255;240m                                                                                              \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m            'custome_name': 'nelson and murdock',\u001b[0m\u001b[48;2;240;255;240m                                                      \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m            'pickup_time': 'June 3 10:00am',\u001b[0m\u001b[48;2;240;255;240m                                                           \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m            'pickup_location': '797 9th Avenue',\u001b[0m\u001b[48;2;240;255;240m                                                       \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m            'dropoff_time': 'June 3 10:30am',\u001b[0m\u001b[48;2;240;255;240m                                                          \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m            'dropoff_location': 'Courthouse, 61 Center Street C/O frank james',\u001b[0m\u001b[48;2;240;255;240m                        \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m            'price': '$23.00'\u001b[0m\u001b[48;2;240;255;240m                                                                          \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m        },\u001b[0m\u001b[48;2;240;255;240m                                                                                             \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m        {\u001b[0m\u001b[48;2;240;255;240m                                                                                              \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m            'custome_name': 'abc flowers',\u001b[0m\u001b[48;2;240;255;240m                                                             \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m            'pickup_time': 'June 2 11:00am',\u001b[0m\u001b[48;2;240;255;240m                                                           \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m            'pickup_location': '21 3rd street',\u001b[0m\u001b[48;2;240;255;240m                                                        \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m            'dropoff_time': 'June 2 5:30pm',\u001b[0m\u001b[48;2;240;255;240m                                                           \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m            'dropoff_location': '75th Ave',\u001b[0m\u001b[48;2;240;255;240m                                                            \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m            'price': '$14.50'\u001b[0m\u001b[48;2;240;255;240m                                                                          \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m        },\u001b[0m\u001b[48;2;240;255;240m                                                                                             \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m        {\u001b[0m\u001b[48;2;240;255;240m                                                                                              \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m            'custome_name': 'polk and wardell',\u001b[0m\u001b[48;2;240;255;240m                                                        \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m            'pickup_time': 'June 3 11:00am',\u001b[0m\u001b[48;2;240;255;240m                                                           \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m            'pickup_location': '331 5th street',\u001b[0m\u001b[48;2;240;255;240m                                                       \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m            'dropoff_time': 'June 3 5:30pm',\u001b[0m\u001b[48;2;240;255;240m                                                           \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m            'dropoff_location': '75th Ave',\u001b[0m\u001b[48;2;240;255;240m                                                            \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m            'price': '$34.50'\u001b[0m\u001b[48;2;240;255;240m                                                                          \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m        }\u001b[0m\u001b[48;2;240;255;240m                                                                                              \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m    ]\u001b[0m\u001b[48;2;240;255;240m                                                                                                  \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m│\u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m}\u001b[0m\u001b[48;2;240;255;240m                                                                                                      \u001b[0m\u001b[48;2;240;255;240m \u001b[0m\u001b[48;2;240;255;240m│\u001b[0m │\n",
       "    │ \u001b[48;2;240;255;240m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m │\n",
       "    ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\n"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pydantic_guard.history.last.tree"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "litellm",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
